//
//  DMCCycleImages.h
//  22-AliPlanet_HomeWork
//
//  Created by dllo on 16/8/4.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "IconTableViewCell.h"
#import "CycleCollecCell.h"
#import "LittleData.h"
#import "UIImageView+DownloadImage.h"

@interface IconTableViewCell () <UICollectionViewDelegate, UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *layout;

@end

@implementation IconTableViewCell

- (void)layoutSubviews {
    [super layoutSubviews];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.contentSize = CGSizeMake(self.contentView.frame.size.width, self.contentView.frame.size.height);
    _layout.itemSize = CGSizeMake((self.contentView.frame.size.width - 2) / 3, CGRectGetHeight(self.bounds));
    _layout.minimumInteritemSpacing = 0;
    _layout.minimumLineSpacing = 1;
    _layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    if (_data) {
        [self.collectionView reloadData];
    }

}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _data.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CycleCollecCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cycle" forIndexPath:indexPath];
    cell.iconLabel.text = _data[indexPath.row].name;
    [cell.iconView asyncDownloadImageWithURL:_data[indexPath.row].picUrl completionHandler:^(NSData *data, UIImage *image) {}];
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        NSLog(@"点击了歌单");
    } else if (indexPath.row == 1) {
        NSLog(@"点击了排行榜");
    } else {
        NSLog(@"点击了歌手");
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
